/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package rpt.bd.cenario;

import javax.swing.JTabbedPane;

/**
 * A classe CCenarioBdEdicao encapsula as instâncias de
 * acesso a informações nas tabelas do banco de dados
 * através de componentes visuais como grades e paineis de diálogo.
 * @author Roberto
 */

public class CCenarioBdEdicao extends CCenarioBd {

    /**************************************************************************/
    /***                                                                    ***/
    /**************************************************************************/

    protected CPainelBdCenarioEdicao fPainelBdCenarioEdicao = null;

    /**************************************************************************/
    /***                                                                    ***/
    /**************************************************************************/

    public CCenarioBdEdicao(
        final String aTitulo,
        final CGlobal aGlobal,
        final Object aPainelTabulador,
        final CPainelBdCenarioEdicao aPainelBdCenario,
        final int aTipoDialogoBd,
        final int[] aValoresIdMestre,
        final CPersistenciaBdCenario aPertinenciaBdMestre,
        final String[] aNomesCampoMestre,
        final String[] aNomesCampoDetalhe,
        final String[] aComparacoes,
        final String[] aNomesCampoMestreHeranca,
        final String[] aNomesCampoDetalheHeranca) {
        //
        super(aTitulo,aGlobal,aPainelTabulador,
            aTipoDialogoBd,aValoresIdMestre,aPertinenciaBdMestre,
            aNomesCampoMestre,aNomesCampoDetalhe,aComparacoes,
            aNomesCampoMestreHeranca,aNomesCampoDetalheHeranca,
            false);
        //
        fPainelBdCenarioEdicao = aPainelBdCenario;
        //
        preparar(true);
    }

    /**************************************************************************/
    /***                                                                    ***/
    /**************************************************************************/

    public CCenarioBdEdicao(
        final String aTitulo,
        final CGlobal aGlobal,
        final int aTipoDialogoBd,
        final CPainelBdCenarioEdicao aPainelBd,
        final JTabbedPane aPainelTabulador) {
        //
        this(aTitulo,aGlobal,aPainelTabulador,
                aPainelBd,aTipoDialogoBd,
                null,null,null,null,null,null,null);
    }

    /**************************************************************************/
    /***                                                                    ***/
    /**************************************************************************/

    @Override
    protected void preparar(
            final boolean aPreparar) {
        if (aPreparar) {
            fPainelBdCenarioEdicao.setCenarioBd(this);
            fPainelBdCenarioEdicao.preparar();
            fEstruturaRegistroBd = fPainelBdCenarioEdicao.getEstruturaRegistroBd(this);
            fPersistenciaBd.setEstruturaRegistroBd(fEstruturaRegistroBd);
            super.preparar(aPreparar);
            fPersistenciaBd.setLiberarEdicao(false,false);
        }
    }

    /**************************************************************************/
    /***                                                                    ***/
    /**************************************************************************/

    @Override
    protected CPersistenciaBd criarPersistenciaBd() {
        return new CPersistenciaBdCenario(this);
    }

    /**************************************************************************/
    /***                                                                    ***/
    /**************************************************************************/

    public CPersistenciaBdCenario getPersistenciaBdCenario() {
        return (CPersistenciaBdCenario)fPersistenciaBd;
    }

    /**************************************************************************/
    /***                                                                    ***/
    /**************************************************************************/

    public CPainelBd getPainelBd() {
        return fPainelBdCenarioEdicao;
    }

    /**************************************************************************/
    /***                                                                    ***/
    /**************************************************************************/

    @Override
    public void getDialogoBd(
            final int aTipoDialogoBd,
            final Object aPainelTabulador) {
        switch (aTipoDialogoBd) {
            case 1: {
                fDialogoGradeBdFormBd = new CDialogoGradeBdFormBd(this);
                fDialogoBd = new CDialogoBdCenarioEdicao(this);
                ((CDialogoBdCenarioEdicao)fDialogoBd).AdicionarDialogoCentral(fDialogoGradeBdFormBd);
                break;
            }
            case 2: {
                fDialogoGradeBdFormBd = new CDialogoGradeBdFormBd(this);
                fDialogoBd = new CDialogoSelecionarBd(this,(CJanelaSelecionarBd)aPainelTabulador);
                ((CDialogoSelecionarBd)fDialogoBd).AdicionarDialogoCentral(fDialogoGradeBdFormBd);
                break;
            }
            case 3: {
                fDialogoBd = fPainelBdCenarioEdicao;
                break;
            }
            default: {
                fDialogoBd = new CDialogoBdCenarioEdicao(this);
                ((CDialogoBdCenarioEdicao)fDialogoBd).AdicionarDialogoCentral(fDialogoBd);
                break;
            }
        }
    }

    /**************************************************************************/
    /***                                                                    ***/
    /**************************************************************************/
}
